<?php

    class LoginSchema extends CakeSchema {
        public  $name = 'login';
        public function before($event = array()) {
            return true;
        }

        public function after($event = array()) {}

        public $login_tokens = array(
            'id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>11,
                'key'=>'primary',
                'default'=>null
            ),
            'user_id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>11,
                'default'=>null
            ),
            'token'=>array(
                'type'=>'string',
                'null'=>false,
                'lenght'=>32,
                'default'=>null
            ),
            'duration'=>array(
                'type'=>'string',
                'null'=>false,
                'lenght'=>32,
                'default'=>null
            ),
            'used'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>1,
                'default'=>'0'
            ),
            'created'=>array(
                'type'=>'datetime',
                'null'=>false,
                'default'=>null
            ),
            'expires'=>array(
                'type'=>'datetime',
                'null'=>false,
                'default'=>null
            ),
            'indexes'=>array(
                'PRIMARY'=>array(
                    'column'=>'id',
                    'unique'=>1
                )
            )
        );

        public $users = array(
            'id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>11,
                'key'=>'primary',
                'default'=>null
            ),
            'user_group_id'=>array(
                'type'=>'integer',
                'null'=>true,
                'lenght'=>11,
                'default'=>null
            ),
            'username'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>100,
                'default'=>null
            ),
            'password'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>255,
                'default'=>null
            ),
            'salt'=>array(
                'type'=>'text',
                'null'=>true,
                'default'=>null
            ),
            'email'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>100,
                'default'=>null
            ),
            'first_name'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>100,
                'default'=>null
            ),
            'last_name'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>100,
                'default'=>null
            ),
            'email_verified'=>array(
                'type'=>'integer',
                'null'=>true,
                'lenght'=>1,
                'default'=>'0'
            ),
            'active'=>array(
                'type'=>'integer',
                'null'=>true,
                'lenght'=>1,
                'default'=>'0'
            ),
            'ip_address'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>50,
                'default'=>null
            ),
            'created'=>array(
                'type'=>'datetime',
                'null'=>true,
                'default'=>null
            ),
            'modified'=>array(
                'type'=>'datetime',
                'null'=>true,
                'default'=>null
            ),
            'indexes'=>array(
                'PRIMARY'=>array(
                    'column'=>'id',
                    'unique'=>1
                ),
                'user'=>array('column'=>'username','unique'=>1),
                'mail'=>array('column'=>'email','unique'=>1),
                'user_grupo'=>array('column'=>'user_group_id','unique'=>0)
            )
        );

        public $user_groups = array(
            'id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>11,
                'key'=>'primary',
                'default'=>null
            ),
            'name'=>array(
                'type'=>'string',
                'null'=>false,
                'lenght'=>100,
                'default'=>null
            ),
            'alias_name'=>array(
                'type'=>'string',
                'null'=>true,
                'lenght'=>100,
                'default'=>null
            ),
            'allowRegistration'=>array(
                'type'=>'integer',
                'null'=>true,
                'lenght'=>1,
                'default'=>'1'
            ),
            'created'=>array(
                'type'=>'datetime',
                'null'=>true,
                'default'=>null
            ),
            'modified'=>array(
                'type'=>'datetime',
                'null'=>true,
                'default'=>null
            ),
            'indexes'=>array(
                'PRIMARY'=>array(
                    'column'=>'id',
                    'unique'=>1
                )
            )
        );

        public $user_group_permissions = array(
            'id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>10,
                'key'=>'primary',
                'default'=>null
            ),
            'user_group_id'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>10,
                'default'=>null
            ),
            'controller'=>array(
                'type'=>'string',
                'null'=>false,
                'lenght'=>50,
                'default'=>null
            ),
            'action'=>array(
                'type'=>'string',
                'null'=>false,
                'lenght'=>100,
                'default'=>null
            ),
            'allowed'=>array(
                'type'=>'integer',
                'null'=>false,
                'lenght'=>1,
                'default'=>'1'
            ),
            'indexes'=>array(
                'PRIMARY'=>array(
                    'column'=>'id',
                    'unique'=>1
                )
            )
        );

        //@newTable

        /**##########################
         * Insert da tabelas
         */

        /*
         INSERT INTO user_groups (id, name, alias_name, "allowRegistration", created, modified) VALUES
      (1, 'Admin', 'Admin', 0, now(), now()),
      (2, 'User', 'User', 1, now(), now()),
      (3, 'Guest', 'Guest', 0, now(), now());

        INSERT INTO users (id, user_group_id, username, password, salt, email, first_name, last_name, email_verified, active, ip_address, created, modified) VALUES
          (1, 1, 'admin', '365caef7fccbdb1ee711f084be9317a7', '1e6d99570a4d37cc29b18c4a6b06e6ed', 'admin@admin.com', 'Admin', '', 1, 1, '', now(), now());

        INSERT INTO user_group_permissions (id, user_group_id, controller, action, allowed) VALUES
          (1, 1, 'Pages', 'display', 1),
          (2, 2, 'Pages', 'display', 1),
          (3, 3, 'Pages', 'display', 1),
          (4, 1, 'UserGroupPermissions', 'index', 1),
          (5, 2, 'UserGroupPermissions', 'index', 0),
          (6, 3, 'UserGroupPermissions', 'index', 0),
          (7, 1, 'UserGroupPermissions', 'update', 1),
          (8, 2, 'UserGroupPermissions', 'update', 0),
          (9, 3, 'UserGroupPermissions', 'update', 0),
          (10, 1, 'UserGroups', 'index', 1),
          (11, 2, 'UserGroups', 'index', 0),
          (12, 3, 'UserGroups', 'index', 0),
          (13, 1, 'UserGroups', 'addGroup', 1),
          (14, 2, 'UserGroups', 'addGroup', 0),
          (15, 3, 'UserGroups', 'addGroup', 0),
          (16, 1, 'UserGroups', 'editGroup', 1),
          (17, 2, 'UserGroups', 'editGroup', 0),
          (18, 3, 'UserGroups', 'editGroup', 0),
          (19, 1, 'UserGroups', 'deleteGroup', 1),
          (20, 2, 'UserGroups', 'deleteGroup', 0),
          (21, 3, 'UserGroups', 'deleteGroup', 0),
          (22, 1, 'Users', 'index', 1),
          (23, 2, 'Users', 'index', 0),
          (24, 3, 'Users', 'index', 0),
          (25, 1, 'Users', 'viewUser', 1),
          (26, 2, 'Users', 'viewUser', 0),
          (27, 3, 'Users', 'viewUser', 0),
          (28, 1, 'Users', 'myprofile', 1),
          (29, 2, 'Users', 'myprofile', 1),
          (30, 3, 'Users', 'myprofile', 0),
          (31, 1, 'Users', 'login', 1),
          (32, 2, 'Users', 'login', 1),
          (33, 3, 'Users', 'login', 1),
          (34, 1, 'Users', 'logout', 1),
          (35, 2, 'Users', 'logout', 1),
          (36, 3, 'Users', 'logout', 1),
          (37, 1, 'Users', 'register', 1),
          (38, 2, 'Users', 'register', 1),
          (39, 3, 'Users', 'register', 1),
          (40, 1, 'Users', 'changePassword', 1),
          (41, 2, 'Users', 'changePassword', 1),
          (42, 3, 'Users', 'changePassword', 0),
          (43, 1, 'Users', 'changeUserPassword', 1),
          (44, 2, 'Users', 'changeUserPassword', 0),
          (45, 3, 'Users', 'changeUserPassword', 0),
          (46, 1, 'Users', 'addUser', 1),
          (47, 2, 'Users', 'addUser', 0),
          (48, 3, 'Users', 'addUser', 0),
          (49, 1, 'Users', 'editUser', 1),
          (50, 2, 'Users', 'editUser', 0),
          (51, 3, 'Users', 'editUser', 0),
          (52, 1, 'Users', 'dashboard', 1),
          (53, 2, 'Users', 'dashboard', 1),
          (54, 3, 'Users', 'dashboard', 0),
          (55, 1, 'Users', 'deleteUser', 1),
          (56, 2, 'Users', 'deleteUser', 0),
          (57, 3, 'Users', 'deleteUser', 0),
          (58, 1, 'Users', 'makeActive', 1),
          (59, 2, 'Users', 'makeActive', 0),
          (60, 3, 'Users', 'makeActive', 0),
          (61, 1, 'Users', 'accessDenied', 1),
          (62, 2, 'Users', 'accessDenied', 1),
          (63, 3, 'Users', 'accessDenied', 1),
          (64, 1, 'Users', 'userVerification', 1),
          (65, 2, 'Users', 'userVerification', 1),
          (66, 3, 'Users', 'userVerification', 1),
          (67, 1, 'Users', 'forgotPassword', 1),
          (68, 2, 'Users', 'forgotPassword', 1),
          (69, 3, 'Users', 'forgotPassword', 1),
          (70, 1, 'Users', 'makeActiveInactive', 1),
          (71, 2, 'Users', 'makeActiveInactive', 0),
          (72, 3, 'Users', 'makeActiveInactive', 0),
          (73, 1, 'Users', 'verifyEmail', 1),
          (74, 2, 'Users', 'verifyEmail', 0),
          (75, 3, 'Users', 'verifyEmail', 0),
          (76, 1, 'Users', 'activatePassword', 1),
          (77, 2, 'Users', 'activatePassword', 1),
          (78, 3, 'Users', 'activatePassword', 1);

        SELECT setval('public.users_id_seq', 2, true);

        SELECT setval('public.user_groups_id_seq', 4, true);

        SELECT setval('public.user_group_permissions_id_seq', 70, true);
        /*Mysql Auto increment
        ALTER USERS tbl AUTO_INCREMENT = 2;
        ALTER USER_GROUPS tbl AUTO_INCREMENT = 4;
        ALTER USER_GROUP_PERMISSIONS tbl AUTO_INCREMENT = 70;
         */
        /**#######################
         * Fim dos Insert
         */
    }
